/*
 * 
 *
 * Authors: Soeren Gebbert, soeren.gebbert@vti.bund.de
 *          Axel Don, axel.don@vti.bund.de
 *
 * Copyright:
 *
 * Johann Heinrich von Thünen-Institut
 * Institut für Agrarrelevante Klimaforschung
 *
 * Phone: +49 (0)531 596 2601
 *
 * Fax:+49 (0)531 596 2699
 *
 * Mail: ak@vti.bund.de
 *
 * Bundesallee 50
 * 38116 Braunschweig
 * Germany
 *
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 2 of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

#include <iostream>
#include <sstream>
#include <fstream>
#include "event_base.h"

using namespace std;

/* -------------------------------------------------------------------------- */
event_base::event_base() {
    this->start = 0;
    this->stop = 0;
    this->frequence = 0;
    this->count = 0;
    this->filename = "";
}

/* -------------------------------------------------------------------------- */
bool event_base::read_base_parameter(ifstream &input) {
    
    char buff[1024];
    size_t pos;
    
    if (input) {
        while (input.getline(buff, 1024)) {

            string line(buff);
            string sub;
            /* Ignore lines with a leading #, its a comment */
            if (line.find("#") != string::npos)
                continue;

            if (line.find("start") != string::npos) {
                pos = line.find("=");
                if (pos != string::npos) {
                    sub = line.substr(pos + 1);
                    stringstream ss(sub);
                    ss >> this->start;
                }
            }
            if (line.find("stop") != string::npos) {
                pos = line.find("=");
                if (pos != string::npos) {
                    sub = line.substr(pos + 1);
                    stringstream ss(sub);
                    ss >> this->stop;
                }
            }
            if (line.find("frequence") != string::npos) {
                pos = line.find("=");
                if (pos != string::npos) {
                    sub = line.substr(pos + 1);
                    stringstream ss(sub);
                    ss >> this->frequence;
                }
            }
        }
    } else {
        cerr << "Unable to read event parameter file " << this->filename << endl;
        return false;
    }
    return true;
}
